//
//  AllMerchantVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/6/4.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "AllMerchantVC.h"
#import "RecommendMerchantCell.h"
#import "RecommendMerchantDetailVC.h"
@interface AllMerchantVC ()

@property (nonatomic, strong) NSArray * dataSource;

@end

@implementation AllMerchantVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setup];
    
    [self loadData];
}

- (void)setup {
    
    self.title = MYLocalizedString(@"HOMEPAGE_BUSINESS", nil);
    
    [self setAutoRowHeight];
    [self registCells:@[@"RecommendMerchantCell"]];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
    self.tableView.tableFooterView = [UIView new];
    
    self.tableView.backgroundColor = kBGColor;
}

- (void)loadData {
    
    [ActivityIndicatorView showHUDAddedTo:self.view];
    @weakify(self);
    [NetAPIManager getAllBusinessWithCityid:self.cityid block:^(NSArray *businessArray, NSError *error) {
        @strongify(self);
        [ActivityIndicatorView hideHUDAddedTo:self.view];
        self.dataSource = businessArray;
        [self.tableView reloadData];
        
    }];
    
}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    RecommendMerchantCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecommendMerchantCell" forIndexPath:indexPath];
    cell.superVC = self;
    MerchantModel *model = self.dataSource[indexPath.row];
    model.isList = YES;
    
    cell.model = model;
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return kScreenWidth /375 * 130;
}

@end
